#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    client = new QTcpSocket;
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_connectpushButton_2_clicked()
{
    QString ip = ui->iplineEdit->text();
    QString port = ui->portlineEdit->text();
    client->connectToHost(QHostAddress(ip),port.toShort());

    connect(client,&QTcpSocket::connected,this,&Widget::connected_notify);
    connect(client,&QTcpSocket::disconnected,this,&Widget::disconnected_notify);
}


void Widget::on_cancelpushButton_clicked()
{
    this->close();
}



void Widget::connected_notify()
{
//    QMessageBox::information(this,"连接提示","连接服务器成功");
    this->hide();
    Chatcli *c = new Chatcli(client);
    c->show();

}

void Widget::disconnected_notify()
{
    QMessageBox::warning(this,"连接提示","连接异常 网络断开");
}
